package com.shadow.cloud.security.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shadow.cloud.security.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {

    /**
     * 基于用户id查询用户权限
     * @param userId 用户id
     * @return 用户的权限
     * 涉及到的表:tb_user_roles,tb_role_menus,tb_menus
     */
    @Select("select distinct m.code " +
            "from cloud_user_role ur " +
            "inner join cloud_role_permission rm on ur.role_id = rm.role_id " +
            "inner join cloud_permission m on rm.permission_id = m.id " +
            "where ur.id = #{userId}")
    List<String> selectUserPermissions(String userId);
}
